﻿<?php
require_once('../../config.php');
define('AJAX_SCRIPT', true);
global $DB;

$param=$_GET["param"];
$id_array= explode(",", $param);
$program_id=$id_array[0];
$block_id=$id_array[1];
$major_id=$id_array[2];
$sql_get_block="";
$sql_get_major="";
$sql_get_subject="";

$div_content="<div id='program_view' style='margin-left:10px;'>";
//truong hop chon program ma ko chon block va major (xem tat ca)
if($block_id=="" && $major_id=="" )
{
	$div_content=$div_content."<div style='height:50px;'></div>";
	$program = $DB->get_records('program', array('program_id'=>$program_id));
	foreach($program as $pro)
	{
		$div_content=$div_content.'<h2 class="headingblock header">'.$pro->program_name.'</h2>';
	}
	$sql_get_block="select * from mdl_body_of_knowledge where bok_id in (select blockofknowledge_id from mdl_subject_major where program_id='".$program_id."' group by blockofknowledge_id)";
	$block_list = $DB->get_records_sql($sql_get_block);
	//lay danh sach cac khoi kien thuc cua 1 chuong trinh dao tao
	foreach($block_list as $block)
	{
		$div_content=$div_content."<h2 class='headingblock header'>".$block->bok_name."</h2>";
		$sql_get_major="select * from mdl_major where  major_id in(select major_id from mdl_subject_major where blockofknowledge_id='".$block->bok_id."' and program_id='".$program_id."')";
		$major_list = $DB->get_records_sql($sql_get_major);
		//lay danh sach cac chuyen nganh của chuong trinh dao tao co khoi kien thuc này
		foreach($major_list as $major)
		{
			$div_content=$div_content."<h3>".$major->major_name."</h3>";
			$sql_get_subject="select * from mdl_subject where subject_id in (select subject_id from mdl_subject_major where program_id='".$program_id."' and blockofknowledge_id='".$block->bok_id."' and major_id='".$major->major_id."')";
			$subject_list = $DB->get_records_sql($sql_get_subject);
			//lấy danh sach cac mon hoc cua chuyen nganh của khối kiến thưc cua chuong trinh dao tao này
			$div_content=$div_content."<table id='".$block->bok_id.$major->major_id."' border=1 class='generalbox'>";
			$div_content=$div_content.'<th class="headingblock header">Subject ID</th>'.
										'<th class="headingblock header">English Name</th>'.
										'<th class="headingblock header">Vietnamese Name</th>'.
										'<th class="headingblock header">Credit</th>'.
										'<th class="headingblock header">LT</th>'.
										'<th class="headingblock header">TH</th>'.
										'<th class="headingblock header">Edit</th>';
			
			foreach($subject_list as $subject)
			{
				$div_content=$div_content.'<tr>'.
                        '<td>'.$subject->subject_id.'</td>'.
						'<td>'.$subject->subject_name_en.'</td>'.
						'<td>'.$subject->subject_name_vn.'</td>'.
						'<td>'.$subject->subject_credit.'</td>'.
						'<td>'.$subject->subject_theory_hr.'</td>'.
						'<td>'.$subject->subject_practice_hr.'</td>'.
						'<td><a onClick="openColorBox(\'quick_edit_subject.php?sid='.$subject->id.'\')" href="#" title="Edit Subject"> Edit </a></td>'.
						'</tr>';
			}
			$div_content=$div_content."</table>";
		}
	}
}
 
//truong hop chon program, chon block ma ko chon major (xem tat ca major cua 1 chuong trinh, 1 block)
else if($block_id!="" && $major_id=="" )
{
		$sql_get_major="select * from mdl_major where  major_id in(select major_id from mdl_subject_major where blockofknowledge_id='".$block_id."' and program_id='".$program_id."')";
		$major_list = $DB->get_records_sql($sql_get_major);
		//lay danh sach cac chuyen nganh của chuong trinh dao tao co khoi kien thuc này
		foreach($major_list as $major)
		{
			$div_content=$div_content."<h3>".$major->major_name."</h3>";
			$sql_get_subject="select * from mdl_subject where subject_id in (select subject_id from mdl_subject_major where program_id='".$program_id."' and blockofknowledge_id='".$block_id."' and major_id='".$major->major_id."')";
			$subject_list = $DB->get_records_sql($sql_get_subject);
			//lấy danh sach cac mon hoc cua chuyen nganh của khối kiến thưc cua chuong trinh dao tao này
			$div_content=$div_content."<table id='".$block_id.$major->major_id."' border=1 class='generalbox'>";
			$div_content=$div_content.'<th class="headingblock header">Subject ID</th>'.
										'<th class="headingblock header">English Name</th>'.
										'<th class="headingblock header">Vietnamese Name</th>'.
										'<th class="headingblock header">Credit</th>'.
										'<th class="headingblock header">LT</th>'.
										'<th class="headingblock header">TH</th>'.
										'<th class="headingblock header">Edit</th>';
			foreach($subject_list as $subject)
			{
				$div_content=$div_content.'<tr>'.
                        '<td>'.$subject->subject_id.'</td>'.
						'<td>'.$subject->subject_name_en.'</td>'.
						'<td>'.$subject->subject_name_vn.'</td>'.
						'<td>'.$subject->subject_credit.'</td>'.
						'<td>'.$subject->subject_theory_hr.'</td>'.
						'<td>'.$subject->subject_practice_hr.'</td>'.
						'<td><a onClick="openColorBox(\'quick_edit_subject.php?sid='.$subject->id.'\')" href="#" title="Edit Subject"> Edit </a></td>'.
						'</tr>';
			}
			$div_content=$div_content."</table>";
		}
}
//truong hop ko chon chon program nhung ko chon block ma lai chon major
//se liet ke ra tat ca cac mon thuoc khoi kien thuc cua 1 major
else if($block_id=="" && $major_id !="" )
{
		$sql_get_block="select * from mdl_body_of_knowledge where bok_id in (select blockofknowledge_id from mdl_subject_major where program_id='".$program_id."' and major_id='".$major_id."' group by blockofknowledge_id)";
		
		$block_list = $DB->get_records_sql($sql_get_block);
		// lay danh sach cac chuyen nganh của chuong trinh dao tao co khoi kien thuc này
		foreach($block_list as $block)
		{
			$div_content=$div_content."<h3>".$block->bok_name."</h3>";
			$sql_get_subject="select * from mdl_subject where subject_id in (select subject_id from mdl_subject_major where program_id='".$program_id."' and blockofknowledge_id='".$block->bok_id."' and major_id='".$major_id."')";
			$subject_list = $DB->get_records_sql($sql_get_subject);
			// lấy danh sach cac mon hoc cua chuyen nganh của khối kiến thưc cua chuong trinh dao tao này
			$div_content=$div_content."<table id='".$block->bok_id.$major_id."' border=1 class='generalbox'>";
			$div_content=$div_content.'<th class="headingblock header">Subject ID</th>'.
										'<th class="headingblock header">English Name</th>'.
										'<th class="headingblock header">Vietnamese Name</th>'.
										'<th class="headingblock header">Credit</th>'.
										'<th class="headingblock header">LT</th>'.
										'<th class="headingblock header">TH</th>'.
										'<th class="headingblock header">Edit</th>';
			foreach($subject_list as $subject)
			{
				$div_content=$div_content.'<tr>'.
                        '<td>'.$subject->subject_id.'</td>'.
						'<td>'.$subject->subject_name_en.'</td>'.
						'<td>'.$subject->subject_name_vn.'</td>'.
						'<td>'.$subject->subject_credit.'</td>'.
						'<td>'.$subject->subject_theory_hr.'</td>'.
						'<td>'.$subject->subject_practice_hr.'</td>'.
						'<td><a onClick="openColorBox(\'quick_edit_subject.php?sid='.$subject->id.'\')" href="#" title="Edit Subject"> Edit </a></td>'.
						'</tr>';
			}
			$div_content=$div_content."</table>";
		}
}
//truong hop chon program, chon block và chon major
else
{
		$sql_get_subject="select * from mdl_subject where subject_id in (select subject_id from mdl_subject_major where program_id='".$program_id."' and blockofknowledge_id='".$block_id."' and major_id='".$major_id."')";
			$subject_list = $DB->get_records_sql($sql_get_subject);
			//lấy danh sach cac mon hoc cua chuyen nganh của khối kiến thưc cua chuong trinh dao tao này
			$div_content=$div_content."<table id='".$block_id.$major_id."' border=1 class='generalbox'>";
			$div_content=$div_content.'<th class="headingblock header">Subject ID</th>'.
										'<th class="headingblock header">English Name</th>'.
										'<th class="headingblock header">Vietnamese Name</th>'.
										'<th class="headingblock header">Credit</th>'.
										'<th class="headingblock header">LT</th>'.
										'<th class="headingblock header">TH</th>'.
										'<th class="headingblock header">Edit</th>';
			foreach($subject_list as $subject)
			{
				$div_content=$div_content.'<tr>'.
                        '<td>'.$subject->subject_id.'</td>'.
						'<td>'.$subject->subject_name_en.'</td>'.
						'<td>'.$subject->subject_name_vn.'</td>'.
						'<td>'.$subject->subject_credit.'</td>'.
						'<td>'.$subject->subject_theory_hr.'</td>'.
						'<td>'.$subject->subject_practice_hr.'</td>'.
						'<td><a onClick="openColorBox(\'quick_edit_subject.php?sid='.$subject->id.'\')" href="#" title="Edit Subject"> Edit </a></td>'.
						'</tr>';
			}
			$div_content=$div_content."</table>";
}
$div_content=$div_content."</div>";
echo $div_content;

?>